using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using SiteManager;
using System.Text;


/// <summary>
/// Summary description for JSFileCreator
/// </summary>
public class JSFileCreator
{
    private const string HospJSFilePath = "../JScript/Hospitals.js";
    private const string MedSchJSFilePath = "../JScript/MedSchools.js";
    public JSFileCreator()
	{
        
	}
    public void CreateHospitalJS()
    {
        string phyPath = HttpContext.Current.Server.MapPath(HospJSFilePath);
        File.Delete(phyPath);
        Manager _objDB = new Manager(true,"ConnectionString");
        SqlDataReader rdr = _objDB.ExecuteQuery("SELECT HName FROM tbl_hospitals");
        StringBuilder sb = new StringBuilder();
        
        sb.Append("var arrHospitals=[");
        while (rdr.Read())
        {
            if (rdr[0].ToString().Trim().Length > 0)
                sb.Append("\"" + rdr[0].ToString().Replace("\"", "&quot;") + "\",");
        }
        sb.Remove(sb.Length - 1, 1); //Remove the last comma
        sb.Append("]");

        StreamWriter sw = File.AppendText(phyPath);
        sw.WriteLine(sb.ToString());
        sw.Close();
    }
    public void CreateMedSchoolJS()
    {
        string phyPath = HttpContext.Current.Server.MapPath(MedSchJSFilePath);
        File.Delete(phyPath);
        Manager _objDB = new Manager(true,"ConnectionString");
        SqlDataReader rdr = _objDB.ExecuteQuery("SELECT MedicalSchool FROM tbl_MedicalSchool");
        StringBuilder sb = new StringBuilder();
        sb.Append("var arrMedicalSchools=[");
        while (rdr.Read())
            sb.Append("\"" + rdr[0].ToString().Replace("\"","&quot;") + "\",");
        sb.Remove(sb.Length - 1, 1); //Remove the last comma
        sb.Append("]");
        StreamWriter sw = File.AppendText(phyPath);
        sw.WriteLine(sb.ToString());
        sw.Close();
    }
}
